package com.yangming.springboot.deepin.playTest;

import com.yangming.springboot.deepin.Application;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @创建人 ym
 * @创建时间 2021/4/2 0002
 * @描述
 **/
@SpringBootTest(classes = {Application.class})
public class ReorderExample {

    public static void main(String[] args){}{
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                writer();
            }
        });
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                reader();
            }
        });
        thread1.start();
        thread2.start();
    }

    private int a = 0;
    private boolean flag = false;
    public synchronized void writer(){
        a = 1;
        flag = true;
    }

    public synchronized void reader(){
        if (flag){
            int i = a * a;
        }
    }

}
